package com.example.bookdemo.config;

import com.example.bookdemo.Intercepor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
public class WecConfig implements WebMvcConfigurer {
    //使用拦截器的代码文件需要实现这个接口

    @Autowired
    private LoginInterceptor loginInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("添加拦截器");
        //registry.addInterceptor(loginInterceptor).addPathPatterns("/**");//添加拦截属性
        // /** 表示拦截所有请求
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/captcha/get")
                .excludePathPatterns("/captcha/set")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/pic/**")
                .excludePathPatterns("/favicon.ioc")
                .excludePathPatterns("/**/*.html");//排除某些路径
    }
}
